package com.zh.note.huawei.onehundred.找车位;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author: zhanghuan
 * @date: 2023/9/4 12:14
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // String line = sc.nextLine();
        String line = "1,0,0,0,0,1,0,0,1,0,1";
        int[] nums = Arrays.stream(line.split(",")).mapToInt(Integer::parseInt).toArray();

        int maxDistance = Integer.MIN_VALUE;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] == 1) {
                continue;
            }
            maxDistance = Math.max(maxDistance, getMinDistance(nums, i));

        }
        System.out.println(maxDistance);
    }

    private static int getMinDistance(int[] nums, int index) {
        int left = 0;
        int right = 0;
        for (int i = 0; i < index; i++) {
            if (nums[i] == 1) {
                left = i;
            }
        }
        for (int i = index; i < nums.length; i++) {
            if (nums[i] == 1) {
                right = i;
                break;
            }
        }
        return Math.min(index - left, right - index);
    }
}
